package com.jmpt.fangbohui.ui.holder;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jmpt.fangbohui.R;
import com.jmpt.fangbohui.bean.NewHouseDetailBean;
import com.jmpt.fangbohui.bean.NewHouseDetailBean.Room;
import com.jmpt.fangbohui.ui.NewHouseDetailActivity;
import com.jmpt.fangbohui.ui.base.BaseViewHolder;

public class NewHouseRoomHolder extends BaseViewHolder<List<NewHouseDetailBean.Room>> {

	LinearLayout rootView;
	
	public NewHouseRoomHolder(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected View initView() {
		rootView = (LinearLayout) View.inflate(mContext, R.layout.rooms_holder, null);
		
		return rootView;
	}

	@Override
	protected void refreshView(List<Room> data) {
		if (data == null || data.size() < 1) {

			rootView.addView(View.inflate(mContext, R.layout.no_more, null));

			return;
		}
		//标题
		rootView.addView(View.inflate(mContext, R.layout.rooms_head_layout, null));
		
		/*
		for (int i = 0; i < data.size(); i++) {
			rootView.addView(getItem(data.get(i)));
		}
		*/
		
		for (int i = 0; i < data.size() && i < 5; i++) {
			rootView.addView(getItem(data.get(i)));
		}
		
		if(data.size() > 5){
			rootView.addView(getMoreView());
		}
		
	}
	
	private View getItem(Room room) {
		RoomItemHolder itemHolder = new RoomItemHolder(mContext);
		itemHolder.setData(room);
		return itemHolder.getRootView();
	}

	private View getMoreView() {
		View view = View.inflate(mContext, R.layout.more_news, null);
		((TextView)view.findViewById(R.id.tv_des)).setText("更多楼层信息");
		view.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO 更多
				((NewHouseDetailActivity)mContext).moreRooms();
			}
		});
		return view;
	}

}
